From ef1bc2923e4184c854730fea269ac44ffabf9906 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 8 Jan 2012 22:18:46 -0500 Subject: [PATCH] Add more tests for GdkRGBA parsing These examples are taken from bug 667485. --- gdk/tests/rgba.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/gdk/tests/rgba.c b/gdk/tests/rgba.c index d23bb96fe9..fa2da629bf 100644 --- a/gdk/tests/rgba.c +++ b/gdk/tests/rgba.c @@ -49,6 +49,14 @@ test_color_parse (void) res = gdk_rgba_parse (&color, "#0080ff"); g_assert (res); g_assert (gdk_rgba_equal (&color, &expected)); + + expected.red = 0.0; + expected.green = 0.0; + expected.blue = 0.0; + expected.alpha = 1.0; + res = gdk_rgba_parse (&color, "rgb(0,0,0)"); + g_assert (res); + g_assert (gdk_rgba_equal (&color, &expected)); } static void @@ -107,12 +115,48 @@ test_color_copy (void) gdk_rgba_free (out); } +static void +test_color_parse_nonsense (void) +{ + GdkRGBA color; + gboolean res; + + g_test_bug ("667485"); + + res = gdk_rgba_parse (&color, "rgb(,,)"); + g_assert (!res); + + res = gdk_rgba_parse (&color, "rgb(%,%,%)"); + g_assert (!res); + + res = gdk_rgba_parse (&color, "rgb(nan,nan,nan)"); + g_assert (!res); + + res = gdk_rgba_parse (&color, "rgb(inf,inf,inf)"); + g_assert (!res); + + res = gdk_rgba_parse (&color, "rgb(1p12,0,0)"); + g_assert (!res); + + res = gdk_rgba_parse (&color, "rgb(5d1%,1,1)"); + g_assert (!res); + + res = gdk_rgba_parse (&color, "rgb(0,0,0)moo"); + g_assert (!res); + + res = gdk_rgba_parse (&color, "rgb(0,0,0) moo"); + g_assert (!res); +} + int main (int argc, char *argv[]) { g_test_init (&argc, &argv, NULL); + g_test_bug_base ("http://bugzilla.gnome.org"); + g_test_add_func ("/rgba/parse", test_color_parse); + g_test_add_func ("/rgba/parse/nonsense", test_color_parse_nonsense); g_test_add_func ("/rgba/to-string", test_color_to_string); g_test_add_func ("/rgba/copy", test_color_copy); -- 2.30.2